package com.sann.demo001;

import com.sann.demo001.ioc.FXNewsProvider;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;

public class BeanFactoryTest {

	public static void main(String[] args) {
		/**
		 * 在BeanFactory之前,我们通常在应用程序入口类的main方法中,自己实例化相应的对象并调用之,如:
		 */
		FXNewsProvider fxNewsProvider = new FXNewsProvider();
		fxNewsProvider.getAndPersistNews();
	}

	/**
	 * 有了BeanFactory后,我们通常只需将"生产图纸"交给BeanFactory,让BeanFactory为我们生产一个FXNewsProvider,如以下
	 * testCase1 ~ testCase3 中任何一种方式皆可.
	 */
	@Test
	public void testCase1(){
		BeanFactory container = new XmlBeanFactory(new ClassPathResource("demo001/beanfactoryawareinject.xml"));
		FXNewsProvider provider = (FXNewsProvider)container.getBean("djNewsProvider");
		provider.getAndPersistNews();
	}

	@Test
	public void testCase2(){
		ApplicationContext container = new ClassPathXmlApplicationContext("demo001/beanfactoryawareinject.xml");
		FXNewsProvider provider = (FXNewsProvider)container.getBean("djNewsProvider");
		provider.getAndPersistNews();
	}

	@Test
	public void testCase3(){
		ApplicationContext container = new FileSystemXmlApplicationContext("demo001/beanfactoryawareinject.xml");
		FXNewsProvider provider = (FXNewsProvider)container.getBean("djNewsProvider");
		provider.getAndPersistNews();
	}



}
